﻿
using Microsoft.AspNetCore.Mvc;
using Zhaoxi.MSACommerce.VerificationServer.Service;

namespace Zhaoxi.MSACommerce.VerificationServer.Controllers
{

    [Route(template: "api/verification/sms")]
    [ApiController]
    public class SmsController(ISmsService smsService) : ControllerBase
    {
        [HttpPost(template: "send")]
        public async Task<IActionResult> SendCode(string phoneNumber)
        {
            var result = await smsService.SendCodeAsync(phoneNumber);
            return result.IsSuccess ? Ok(result.Value) : BadRequest(result.Errors);
        }

        [HttpPost(template: "verify")]
        public async Task<IActionResult> VerifyCode(string phoneNumber, string code)
        {
            var result = await smsService.VerifyCodeAsync(phoneNumber, code);
            return result.IsSuccess ? Ok(result.Value) : BadRequest(result.Errors);
        }
    }
}
